package com.xiaomi.eco.web.controller;

import com.xiaomi.eco.dal.entity.OFeedbackDataEntity;
import com.xiaomi.eco.dal.query.ApiResult;
import com.xiaomi.eco.dal.query.ApiResultDataRes;
import com.xiaomi.eco.dal.query.PageResult;
import com.xiaomi.eco.dal.req.TaskDetailReq;
import com.xiaomi.eco.dal.req.TaskEditReq;
import com.xiaomi.eco.dal.req.TaskQueryReq;
import com.xiaomi.eco.dal.res.SearchRes;
import com.xiaomi.eco.dal.res.TaskDetailRes;
import com.xiaomi.eco.dal.res.TaskQueryRes;
import com.xiaomi.eco.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/quality/task")
public class TaskController {

    @Autowired
    private TaskService taskService;

    @RequestMapping(value = "/query", method = RequestMethod.POST)
    public ApiResultDataRes<PageResult<List<TaskQueryRes>>> queryTask(@RequestBody TaskQueryReq taskQueryReq) {
        return ApiResultDataRes.addSuccess(taskService.queryTask(taskQueryReq));
    }

    @RequestMapping(value = "/getTaskDetail", method = RequestMethod.POST)
    public ApiResultDataRes<PageResult<List<TaskDetailRes>>> getTaskDetail(@RequestBody TaskDetailReq taskDetailReq) {
        return ApiResultDataRes.addSuccess(taskService.getTaskDetail(taskDetailReq));
    }

    @RequestMapping(value = "/batchEdit", method = RequestMethod.POST)
    public ApiResult saveTask(@RequestBody List<TaskEditReq> taskEditReqList) {
        taskService.saveTask(taskEditReqList);
        return ApiResult.addSuccess();
    }

    @RequestMapping(value = "/queryL4", method = RequestMethod.GET)
    public ApiResultDataRes<List<SearchRes>> queryL4() {
        return ApiResultDataRes.addSuccess(taskService.queryL4());
    }

}
